<div class="bjui-pageContent" id="process-Product-select">
    <div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
        <form data-toggle="ajaxsearch" data-options="{searchDatagrid:$.CurrentDialog.find('#dg-process-product-list')}">
            <fieldset>
                <div style="margin:0; padding:1px 5px 5px;">
                    <input type="hidden" id="id" value="{{$id}}">
                    <input type="hidden" id="process_product_id" value="{{$process_product_id}}">
                     <button type="button" class="btn-green" data-icon="save" onClick="saveInfo();">保存</button>
                </div>
            </fieldset>
        </form>
    </div>
    <table id="dg-process-product-list" data-toggle="datagrid" data-options="{
        width: '100%',
        height: '100%',
        gridTitle: '',
        showToolbar: false,
        toolbarItem:false,
        showCheckboxcol: true,
        {{--editMode: 'dialog',--}}
        local: 'local',
        dataUrl: '/admin/pro-pro/process-product-list-for-select',
        inlineEditMult: false,
        isTree: 'cat_name',
        addLocation:false,
        fieldSortable: false,
        columnMenu: false,
        paging: false,
    }">
        <thead>
        <tr>
            <th data-options="{name:'title', align:'center', width:300, rule:'required'}">半成品</th>
        </tr>
        </thead>
    </table>
</div>>

<script type="text/javascript">
    function saveInfo(){
          var id = $('#id').val();
          var old_product_id = $('#process_product_id').val();
          var product_id;
          var product_name = '选择';
          var data = $('#dg-process-product-list').data('selectedDatas');

          console.log(data);

          if(data){
             $.each(data,function(i,item){
                    if(old_product_id!=product_id){
                        product_id = item['id'];
                        product_name = item['title'];
                        return false;
                    }
              });
          }

//          alert(product_id);
//          alert(product_name);

          $('#process_product_id_choose').text(product_name);
          $('#process_product_id').val(product_id);
          BJUI.dialog('close', 'process-product-list-for-select-dialog')
     }

    $(document).on(BJUI.eventType.afterInitUI, function(event) {
        initCheckbox();
    });

    function initCheckbox(){
        var product_id = $('#process_product_id').val();
        if(product_id){
            var data = $('#dg-process-product-list').data('allData');
               for(i = 0; i<data.length;i++){
                   if(data[i].id == product_id){
                        $('#dg-process-product-list').datagrid('selectedRows',i);
                   }
               }
        }
    }
</script>